/**
 * 
 */
package com.netscenery.yang.model;

import java.util.ArrayList;
import java.util.Stack;

import org.jdom2.Element;

import com.netscenery.util.ErrTag;
import com.netscenery.util.ILinkData;
import com.netscenery.util.Link;
import com.netscenery.util.QName;
import com.netscenery.yang.YangKeyword;
import com.netscenery.yang.YangStatement;
import com.netscenery.yang.designer.MapInfo;
import com.netscenery.yang.parser.YangParserException;

/**
 * @author chong
 *
 */
public abstract class DataDefElement extends Entity implements ILinkData {
	protected DataDefElement parent;
	
	protected DataDefElement next;
	protected DataDefElement pre;
	
	protected String description;
	protected String reference;
	protected Status status = Status.CURRENT;
	protected String when;
	protected ArrayList<String> if_features;
	/**
	 * 
	 */
	public DataDefElement() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param env
	 * @param name
	 * @throws ModelException 
	 */
	public DataDefElement(Env env, String name) throws ModelException {
		super(env, name);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param env
	 * @param qname
	 */
	public DataDefElement(Env env, QName qname) {
		super(env, qname);
		// TODO Auto-generated constructor stub
	}
	/**
	 * @return the when
	 */
	public String getWhen() {
		return when;
	}

	/**
	 * @param when the when to set
	 */
	public void setWhen(String when) {
		
		this.when = when;
	}

	/**
	 * @return the parent
	 */
	public DataDefElement getParent() {
		return parent;
	}

	/**
	 * @param parent the parent to set
	 */
	public void setParent(DataDefElement parent) {
		this.parent = parent;
	}


	/**
	 * @return the next
	 */
	public DataDefElement getNext() {
		return next;
	}

	/**
	 * @param next the next to set
	 */
	public void setNext(DataDefElement next) {
		this.next = next;
	}

	/**
	 * @return the pre
	 */
	public DataDefElement getPre() {
		return pre;
	}

	/**
	 * @param pre the pre to set
	 */
	public void setPre(DataDefElement pre) {
		this.pre = pre;
	}

	
	
	public boolean checkIf_feature(String feature){
		if (null == feature){
			return false;
		}
		Module m = env.getCurModule();
		if (null == m){
			return false;
		}
		QName qFeature = new QName(feature);
		if (qFeature.isQName()){
			String prefix = qFeature.getPrefix();
			String localName = qFeature.getLocalName();
			if (null == prefix || null == localName){
				return false;
			}
			Module imp = m.getModule(prefix);
			if (null == imp ){
				return false;
			}
			
			if (null == imp.getFeature(localName)){
				return false;
			}
	
		}
		else {
			if (null == m.getFeature(feature)){
				return false;
			}
		}
		return true;
	}
	public boolean addIf_feature(String feature){
		if (null == feature){
			return false;
		}
		if (false == checkIf_feature(feature)){
			return false;
		}
		if (null == if_features){
			if_features = new ArrayList<String>(1);
		}
		return if_features.add(feature);
	}
	
	public String getIf_feature(int index){
		if (null == if_features){
			return null;
		}
		return if_features.get(index);
	}
	
	public String removeIf_feature(int index){
		if (null == if_features){
			return null;
		}
		return if_features.remove(index);
	}
	
	public int getIf_featuresNumber(){
		if (null == if_features){
			return 0;
		}
		
		return if_features.size();
	}

	public abstract String getPath();	
	public abstract String getPathByPrefix(String prefix);
	public abstract String getQualifiedPath();


	/* (non-Javadoc)
	 * @see com.netscenery.yang.model.ModelElement#isFieldMandatory(java.lang.String)
	 */
	@Override
	public boolean isFieldMandatory(String field) {
		// TODO Auto-generated method stub
		return false;
	}

	/* (non-Javadoc)
	 * @see com.netscenery.yang.model.ModelElement#getMapInfo()
	 */
	@Override
	public MapInfo getMapInfo() throws SecurityException, NoSuchMethodException {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see com.netscenery.yang.model.ModelElement#compare(java.lang.Object)
	 */
	@Override
	public int compare(Object o) {
		// TODO Auto-generated method stub
		return super.compare(o);
	}

	/* (non-Javadoc)
	 * @see com.netscenery.yang.model.ModelElement#update()
	 */
	@Override
	public void update() {
		// TODO Auto-generated method stub
		
	}

}
